import { getGameObjectById } from "../engine";
import { Behaviour } from "../engine/Behaviour";
import { TextRenderer } from "../engine/TextRenderer";
import { Transform } from "../engine/Transform";
import { number } from "../engine/validators/number";
import { Display } from "./Display";




export class BillSystem extends Behaviour {
    private currentSpeed = 0;
    Id:String;
    IsSold_ChilliSource=false;
    IsSold_SuanRong=false;
    IsSold_CongHua=false;
    IsSold_Bacon=false;
    IsSold_Chicken=false;
    IsSold_BJUTBox=false;
    currentsum:number;
    onStart() {
        //let currentsum:number;
        let cost:number;
        let rental=20;
        let fee:number;
        let profit:number;
        let income:number;

        this.gameObject.onClick = () => {
            this.Id=this.gameObject.id;
            switch(this.Id){

                case "UI_button_money_ChilliSauce":{
                    this.currentsum=Number(getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text);
                    income=Number(getGameObjectById('Text_Income').getBehaviour(TextRenderer).text);
                    cost=Number(getGameObjectById('Text_cost').getBehaviour(TextRenderer).text);
                    fee=Number(getGameObjectById('Text_Fee').getBehaviour(TextRenderer).text);
                    profit=Number(getGameObjectById('Text_profit').getBehaviour(TextRenderer).text);
                    if(this.currentsum>=10){
                         this.currentsum-=10;
                         cost+=10;
                         profit=(income+fee)-(cost+rental);
                         getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=String(this.currentsum.toFixed(2));
                         getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=String(cost);
                         getGameObjectById('Text_profit').getBehaviour(TextRenderer).text=String(profit);
                         getGameObjectById('UI_button_moneyPurchased_ChilliSource').getBehaviour(Display).IsActive=true;
                         this.IsSold_ChilliSource=true;
                         //显示辣酱
                        getGameObjectById("spicysauce").getBehaviour(Display).IsActive = true

                    }else{
                        getGameObjectById('UI_hintFrame_shop').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_hintFrame_shop_cancel').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_money_decoration').getBehaviour(Display).IsActive=true;
                        getGameObjectById('Text_Title_buy').getBehaviour(Display).IsActive=true;
                        getGameObjectById('Text_CannotBuy').getBehaviour(Display).IsActive=true;
                    }     
                    break;
                }
                case "UI_button_money_SunRong":{
                    this.currentsum=Number(getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text);
                    cost=Number(getGameObjectById('Text_cost').getBehaviour(TextRenderer).text);
                    income=Number(getGameObjectById('Text_Income').getBehaviour(TextRenderer).text);
                    fee=Number(getGameObjectById('Text_Fee').getBehaviour(TextRenderer).text);
                    profit=Number(getGameObjectById('Text_profit').getBehaviour(TextRenderer).text);
                    if(this.currentsum>=10){
                        this.currentsum-=10;
                        cost+=10;
                        profit=(income+fee)-(cost+rental);
                        getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=String(this.currentsum.toFixed(2));
                        getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=String(cost);
                        getGameObjectById('Text_profit').getBehaviour(TextRenderer).text=String(profit);
                        getGameObjectById('UI_button_moneyPurchased_SuanRong').getBehaviour(Display).IsActive=true;
                        this.IsSold_SuanRong=true;
                        //显示蒜蓉
                        getGameObjectById("suanrong").getBehaviour(Display).IsActive = true
                    }else{
                        getGameObjectById('UI_hintFrame_shop').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_hintFrame_shop_cancel').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_money_decoration').getBehaviour(Display).IsActive=true;
                        getGameObjectById('Text_Title_buy').getBehaviour(Display).IsActive=true;
                        getGameObjectById('Text_CannotBuy').getBehaviour(Display).IsActive=true;
                    }
                    break;
                }
                case "UI_button_money_Conghua":{
                    this.currentsum=Number(getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text);
                    cost=Number(getGameObjectById('Text_cost').getBehaviour(TextRenderer).text);
                    fee=Number(getGameObjectById('Text_Fee').getBehaviour(TextRenderer).text);
                    income=Number(getGameObjectById('Text_Income').getBehaviour(TextRenderer).text);
                    profit=Number(getGameObjectById('Text_profit').getBehaviour(TextRenderer).text);
                    if(this.currentsum>=10){
                        this.currentsum-=10;
                        cost+=10;
                        profit=(income+fee)-(cost+rental);
                    getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=String(this.currentsum.toFixed(2));
                    getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=String(cost);
                    getGameObjectById('Text_profit').getBehaviour(TextRenderer).text=String(profit);
                    getGameObjectById('UI_button_moneyPurchased_CongHua').getBehaviour(Display).IsActive=true;
                    this.IsSold_CongHua=true;
                    //显示蒜蓉
                    getGameObjectById("conghua").getBehaviour(Display).IsActive = true
                    }else{
                        getGameObjectById('UI_hintFrame_shop').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_hintFrame_shop_cancel').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_money_decoration').getBehaviour(Display).IsActive=true;
                        getGameObjectById('Text_Title_buy').getBehaviour(Display).IsActive=true;
                        getGameObjectById('Text_CannotBuy').getBehaviour(Display).IsActive=true;
                    }
                    break;
                }
                case "UI_button_money_Bacon":{
                    this.currentsum=Number(getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text);
                    cost=Number(getGameObjectById('Text_cost').getBehaviour(TextRenderer).text);
                    income=Number(getGameObjectById('Text_Income').getBehaviour(TextRenderer).text);
                    fee=Number(getGameObjectById('Text_Fee').getBehaviour(TextRenderer).text);
                    profit=Number(getGameObjectById('Text_profit').getBehaviour(TextRenderer).text);
                    if(this.currentsum>=50){
                        this.currentsum-=50;
                        cost+=50;
                        profit=(income+fee)-(cost+rental);
                    getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=String(this.currentsum.toFixed(2));
                    getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=String(cost);
                    getGameObjectById('Text_profit').getBehaviour(TextRenderer).text=String(profit);
                    getGameObjectById('UI_button_moneyPurchased_Bacon').getBehaviour(Display).IsActive=true;
                    this.IsSold_Bacon=true; 
                    //显示培根
                    getGameObjectById("bacon").getBehaviour(Display).IsActive = true
                    
                    }else{
                        getGameObjectById('UI_hintFrame_shop').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_hintFrame_shop_cancel').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_money_decoration').getBehaviour(Display).IsActive=true;
                        getGameObjectById('Text_Title_buy').getBehaviour(Display).IsActive=true;
                        getGameObjectById('Text_CannotBuy').getBehaviour(Display).IsActive=true;
                    }
                    break;
                }
                case "UI_button_money_Chicken":{
                    this.currentsum=Number(getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text);
                    cost=Number(getGameObjectById('Text_cost').getBehaviour(TextRenderer).text);
                    income=Number(getGameObjectById('Text_Income').getBehaviour(TextRenderer).text);
                    fee=Number(getGameObjectById('Text_Fee').getBehaviour(TextRenderer).text);
                    profit=Number(getGameObjectById('Text_profit').getBehaviour(TextRenderer).text);
                    if(this.currentsum>=50){
                        this.currentsum-=50;
                        cost+=50;
                        profit=(income+fee)-(cost+rental);
                    getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=String(this.currentsum.toFixed(2));
                    getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=String(cost);
                    getGameObjectById('Text_profit').getBehaviour(TextRenderer).text=String(profit);
                    getGameObjectById('UI_button_moneyPurchased_Chicken').getBehaviour(Display).IsActive=true;
                    this.IsSold_Chicken=true;
                    //显示鸡肉
                    getGameObjectById("chiken").getBehaviour(Display).IsActive = true
                    }else{
                        getGameObjectById('UI_hintFrame_shop').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_hintFrame_shop_cancel').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_money_decoration').getBehaviour(Display).IsActive=true;
                        getGameObjectById('Text_Title_buy').getBehaviour(Display).IsActive=true;
                        getGameObjectById('Text_CannotBuy').getBehaviour(Display).IsActive=true;
                    }
                   
                    break;
                }
                case "UI_button_money_BJUTBox":{
                    this.currentsum=Number(getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text);
                    cost=Number(getGameObjectById('Text_cost').getBehaviour(TextRenderer).text);
                    fee=Number(getGameObjectById('Text_Fee').getBehaviour(TextRenderer).text);
                    income=Number(getGameObjectById('Text_Income').getBehaviour(TextRenderer).text);
                    profit=Number(getGameObjectById('Text_profit').getBehaviour(TextRenderer).text);
                    if(this.currentsum>=20){
                        this.currentsum-=20;
                        cost+=20;
                        profit=(income+fee)-(cost+rental);
                    getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=String(this.currentsum.toFixed(2));
                    getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=String(cost);
                    getGameObjectById('Text_profit').getBehaviour(TextRenderer).text=String(profit);
                    getGameObjectById('UI_button_moneyPurchased_BJUTBox').getBehaviour(Display).IsActive=true;
                    this.IsSold_BJUTBox=true;  
                    //显示bjut
                    getGameObjectById("package").getBehaviour(Display).IsActive = false
                    getGameObjectById("packageBJUT").getBehaviour(Display).IsActive = true

                    }else{
                        getGameObjectById('UI_hintFrame_shop').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_hintFrame_shop_cancel').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_money_decoration').getBehaviour(Display).IsActive=true;
                        getGameObjectById('Text_Title_buy').getBehaviour(Display).IsActive=true;
                        getGameObjectById('Text_CannotBuy').getBehaviour(Display).IsActive=true;
                    }
                   
                    break;
                }
                default:{
                    break;
                }
    
            }
            
        };
    }

    onTick(duringTime: number) {
        
    }
}
